package com.zhuge_new.Fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;
import com.zhuge_new.Adapter.IndiectAdapter;
import com.zhuge_new.Base.BaseFragment;
import com.zhuge_new.R;
import com.zhuge_new.bean.IndirectBean;
import com.zhuge_new.http.StringDialogCallback;
import com.zhuge_new.share.BaseHttp;
import com.zhuge_new.untils.DataParse;
import com.zhuge_new.untils.PreferencesUtils;

/**
 * Created by lenovo on 2018-09-15.
 */

public class IndirectFragment extends BaseFragment {

    private SwipeMenuRecyclerView recyclerView;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_indirect, container, false);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        init_title();
        getData();
    }

    @Override
    public void init_title() {
        super.init_title();
        recyclerView = getActivity().findViewById(R.id.recycle_list);
    }

    @Override
    public void getData() {
        super.getData();
        OkGo.<String>post(BaseHttp.user_children_datas)
                .headers("token", PreferencesUtils.getString(getContext(), "token"))
                .params("grade", "3")
                .execute(new StringDialogCallback(getActivity()) {
                    @Override
                    public void onSuccessResponse(Response<String> response, String msg, String msgCode) {
                        IndirectBean indirectBean= (IndirectBean) new DataParse().getBean(response.body(),IndirectBean.class,0);
                        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
                        IndiectAdapter indiectAdapter=new IndiectAdapter(getActivity(),indirectBean.getLs());
                        recyclerView.setAdapter(indiectAdapter);
                    }
                });
    }
}
